package com.woniuxy.core.mapper;

import com.woniuxy.entity.DTO.ShopOrderDTO;
import com.woniuxy.entity.ShopOrder;
import com.woniuxy.entity.UserCoupon;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @Author hq
 * @Date 2025/7/14$ 12:06$
 * @Description TODO
 * @Params $
 * @Return $
 **/
@Mapper
public interface ShopOrderMapper {
    /**
     * 创建订单
     * @param order
     */
    void insert( ShopOrder order);
    /**
     * 查询订单信息
     * @param shopOrder
     * @return
     */
    List<ShopOrderDTO> queryShopOrder(ShopOrder shopOrder);
    /**
     * 根据订单id查询订单信息
     * @param orderId
     */

    ShopOrderDTO getById(Integer orderId);

    /**
     * 修改订单状态
     * @param orderId
     */
    @Update("update shop_order set status=2 where id=#{orderId}")
    void updateOrderStatus( @Param("orderId") Integer orderId);
    ////提交评价根据shopOrder表里的id
    @Update("update shop_order set comment=#{commentInfo},status = 6 where id=#{orderId}")
    void addComment(@Param("orderId") Integer orderId,@Param("commentInfo")String commentInfo);
    /**
     * 根据优惠券id查询优惠券信息
     * @param couponId
     * @return
     */
    @Select("select * from user_coupon where coupon_id=#{couponId}")
    UserCoupon getUserCouponById(Integer couponId);
    /**
     * 根据订单编号查询订单信息
     * @param orderNumber
     * @return
     */
    @Select("select * from shop_order where order_number=#{orderNumber}")
    ShopOrder getByOrderByNumber(String orderNumber);
    /**
     * 根据订单编号修改订单状态
     * @param orderNumber
     * @param code
     */
    @Update("update shop_order set status=#{code} where order_number=#{orderNumber}")
    void updateOrderStatusByNumber(@Param("orderNumber") String orderNumber, @Param("code") int code);
    @Update("update shop_order set payment_time=#{paymentTime} where order_number=#{orderNumber}")
    void updatePaymentInfo(@Param("orderNumber") String orderNumber,  @Param("paymentTime") Date paymentTime);
    @Update("update shop_order set status=4 where id= #{orderId}")
    void confirmOrder(Integer orderId);
}
